package com.wits.qso.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

import com.wits.platform.common.utils.StringUtil;

/**
 * 
 * @see 讨论项
 *
 */
@Entity
@Table(name="qso_discuss_items")
public class DiscussItems implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 9060277332523885637L;
	
	private String id;
	
	/** 讨论组Id **/
	private String groupId;
	
	/** 消息发送者id **/
	private String sendUserId;
	
	/** 消息发送者名字  **/
	private String sendUserName;
	
	/** 消息内容  **/
	private String context;
	
	
	/** 发送日期 **/
	private String sendDate;

	/** 发送时间 **/
	private String sendTime;
	
	
	/** 消息域 (非持久化字段) **/
	private String domain;

	/** 消息命令  (非持久化字段) **/
	private String command;
	
	/** 其他附加数据   非持久化 **/
	private Object data;
	
	public DiscussItems(){
		
	}

	public DiscussItems(String groupId,String userId,String userName){
		this.groupId=groupId;
		this.sendUserId=userId;
		this.sendUserName=userName;
	}
	
	public DiscussItems(String groupId,String userId,String userName,String context){
		this.groupId=groupId;
		this.sendUserId=userId;
		this.sendUserName=userName;
		this.context=context;
	}
	
	@Id
	@GenericGenerator(name = "idGen", 
					strategy = "com.wits.platform.common.id.generator.IDGenerator",
					parameters={ 
								@Parameter(name = "segment_value", value = "QSO_DISCUSS_ITEMS_ID"), 
								@Parameter(name="table_name",value="wits_id_generator"),
								@Parameter(name="value_column_name",value="gen_value"),
								@Parameter(name="segment_column_name",value="gen_name"),
								@Parameter(name="segment_value_length",value="36"),
								@Parameter(name="sq_format",value=""), 
								@Parameter(name="sq_prefix",value="") 
					})
	@GeneratedValue(generator = "idGen")
	@Column(name = "id", nullable = false, insertable = true, updatable = false, length = 36)
	public String getId() {
		return id;
	}



	public void setId(String id) {
		this.id = id;
	}



	@Column(name="group_id",length=36)
	public String getGroupId() {
		return groupId;
	}



	public void setGroupId(String groupId) {
		this.groupId = groupId;
	}


	@Column(name="send_user_id",length=36)
	public String getSendUserId() {
		return sendUserId;
	}



	public void setSendUserId(String sendUserId) {
		this.sendUserId = sendUserId;
	}


	@Column(name="send_user_name",length=50)
	public String getSendUserName() {
		return sendUserName;
	}



	public void setSendUserName(String sendUserName) {
		this.sendUserName = sendUserName;
	}


	@Column(name="context",length=500)
	public String getContext() {
		return context;
	}



	public void setContext(String context) {
		this.context = context;
	}

	@Column(name="send_date",length=10)
	public String getSendDate() {
		return sendDate;
	}

	public void setSendDate(String sendDate) {
		this.sendDate = sendDate;
	}

	@Column(name="send_time",length=8)
	public String getSendTime() {
		return sendTime;
	}

	public void setSendTime(String sendTime) {
		this.sendTime = sendTime;
	}
	
	@Transient
	public String getDomain() {
		return domain;
	}

	public void setDomain(String domain) {
		this.domain = domain;
	}
	
	@Transient
	public String getCommand() {
		return command;
	}

	public void setCommand(String command) {
		this.command = command;
	}
	
	@Transient
	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	@Override
	public String toString() {
		return "{\"domain\":\""+domain+"\",\"command\":\"" + command + "\",\"sender\":\"" + sendUserId
				+ "\",\"text\":\"" + StringUtil.escape(context) + "\",\"sendTime\":\"" + sendTime + "\",\"data\":\""+data+"\"}";
	}


}
